#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "sort.h"
// 检查v是否为升序序列，是返回true，否则返回false
bool Check(std::vector<int>& v) {
  int len = v.size(), i;
  if (len == 0 || len == 1) return true;
  int pre = v[0];
  for (i = 1; i < len; i++) {
    if (pre > v[i]) return false;
    pre = v[i];
  }
  return true;
}

TEST_CASE("sort", "[common]") {
  std::vector<int> v{1, 8, 3, 89, 0, -342, 90, -87, 987, 6};
  SECTION("bubble sort") {
    BubbleSort3(v);
    REQUIRE(Check(v));
  }
  SECTION("insert sort") {
    InsertSort(v);
    REQUIRE(Check(v));
  }
  SECTION("select sort") {
    SelectSort(v);
    REQUIRE(Check(v));
  }
  SECTION("shell sort") {
    ShellSort(v);
    REQUIRE(Check(v));
  }
  SECTION("heap sort") {
    // Print(v);
    HeapSort(v);
    REQUIRE(Check(v));
    // Print(v);
  }
  SECTION("merge sort") {
    MergeSort(v, 0, v.size() - 1);
    REQUIRE(Check(v));
  }
  SECTION("quick sort") {
    QuickSort(v, 0, v.size() - 1);
    REQUIRE(Check(v));
  }
  SECTION("counting sort") {
    std::vector<int> v1{1, 8, 3, 89, 0, 34, 90, 89, 92, 6};
    CountingSort(v1);
    REQUIRE(Check(v1));
  }
}